home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pasclern.zip / CHAP1.TXT < prev    next >
Text File  |  1993-04-01  |  6KB  |  125 lines

  1.                  CHAPTER 1 - What is a computer program?
  2.  
  3.  
  4.             If  you are a complete novice to computers you will find 
  5.         the  information in this chapter useful.    f  however,  you 
  6.         have   had  some  experience  with  programming,   you   can 
  7.         completely  ignore this chapter.   It will deal with  a  few 
  8.         fundamentals  of  computers  in general and  will  introduce 
  9.         nothing that is specific to Pascal.
  10.  
  11.                          WHAT IS A COMPUTER PROGRAM?
  12.  
  13.             A  computer is nothing but a very dumb machine that  has 
  14.         the ability to perform mathematical operations very  rapidly 
  15.         and  very accurately,  but it can do nothing without the aid 
  16.         of  a program written by a human being.   Moreover,  if  the 
  17.         human  being  writes  a program that turns  good  data  into 
  18.         garbage,   the  computer  will  very  obediently,  and  very 
  19.         rapidly, turn the good data into garbage.  It is possible to 
  20.         write  a  computer program with one small error in  it  that 
  21.         will do that very thing.   It is up to the human  programmer 
  22.         to design the program to achieve the desired results.
  23.  
  24.             A  computer  program  is  simply a  "recipe"  which  the 
  25.         computer  will use on the input data to derive  the  desired 
  26.         output data.  It is similar to the recipe for baking a cake.  
  27.         The  input data is comparable to the ingredients,  including 
  28.         the heat supplied by the oven.  The program is comparable to 
  29.         the recipe instructions to mix,  stir, wait, heat, cool, and 
  30.         all  other  possible operations  on  the  ingredients.   The 
  31.         output  of the computer program can be compared to the final 
  32.         cake sitting on the counter ready to be cut and  served.   A 
  33.         computer  program  then is composed of two parts,  the  data 
  34.         upon  which  the  program operates,  and  the  program  that 
  35.         operates on the data.   The data and program are inseparable 
  36.         as implied by the last sentence.
  37.  
  38.                              WHAT ARE CONSTANTS?
  39.  
  40.             Nearly  any computer program requires some numbers  that 
  41.         never  change throughout the program.   They can be  defined 
  42.         once and used as often as needed during the operation of the 
  43.         program.   To  return to the recipe analogy,  once you  have 
  44.         defined  how  big  a tablespoon is,  you can  use  the  same 
  45.         tablespoon without regard to what you are measuring with it.  
  46.         When writing a computer program, you can define the value of 
  47.         PI  =  3.141592,  and continue to use it wherever  it  makes 
  48.         sense knowing that it is available, and correct.
  49.  
  50.                              WHAT ARE VARIABLES?
  51.  
  52.             In  addition to constants,  nearly any computer  program 
  53.         uses  some  numbers  that change  in  value  throughout  the 
  54.         program.   They can be defined as variables, then changed to 
  55.  
  56.  
  57.                                 Page 4
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                  CHAPTER 1 - What is a computer program?
  68.  
  69.  
  70.         any  values  that make sense to the proper operation of  the 
  71.         program.   An  example  would be the number of eggs  in  the 
  72.         above  recipe.   If a single layer of cake required 2  eggs, 
  73.         then a triple layer cake would require 6 eggs.   The  number 
  74.         of eggs would therefore be a variable.
  75.  
  76.                   HOW DO WE DEFINE CONSTANTS OR VARIABLES?
  77.  
  78.             All constants and variables have a name and a value.  In 
  79.         the last example,  the name of the variable was "eggs",  and 
  80.         the  value was either 2 or 6 depending on when we looked  at 
  81.         the  stored data.   In a computer program the constants  and 
  82.         variables  are  given names in much the same  manner,  after 
  83.         which  they  can store any value within the  defined  range.  
  84.         Any  computer  programming  language has a  means  by  which 
  85.         constants or variables can be first named,  then assigned  a 
  86.         value.   The  means  for doing this in Pascal will be  given 
  87.         throughout the remainder of this tutorial.
  88.  
  89.                         WHAT IS SO GOOD ABOUT PASCAL?
  90.  
  91.             Some  computer languages allow the programmer to  define 
  92.         constants and variables in a very haphazard manner and  then 
  93.         combine data in an even more haphazard manner.  For example, 
  94.         if you added the number of eggs, in the above recipe, to the 
  95.         number  of  cups  of  flour,  you would  arrive  a  a  valid 
  96.         mathematical  addition,  but  a totally meaningless  number.  
  97.         Some  programming languages would allow you to do just  such 
  98.         an addition and obediently print out the meaningless answer.  
  99.         Since  Pascal  requires  you to set up  your  constants  and 
  100.         variables in a very precise manner,  the possibility of such 
  101.         a  meaningless answer is minimized.   A well written  Pascal 
  102.         program has many cross checks to minimize the possibility of 
  103.         a completely scrambled and meaningless output.
  104.  
  105.             Notice  however,  in the last statement,  that  a  "well 
  106.         written"  Pascal program was under discussion.   It is still 
  107.         up to the programmer to define the data structure in such  a 
  108.         way that the program can prevent garbage generation.  In the 
  109.         end,  the  program will be no better than the analysis  that 
  110.         went into the program design.
  111.  
  112.             If you are a novice programmer, do not be intimidated by 
  113.         any  of  the above statements.   Pascal is a well  designed, 
  114.         useful tool that has been used successfully by many computer 
  115.         novices and professionals.  With these few warnings, you are 
  116.         ready to begin.
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.                                 Page 5
  124.  
  125.